package com.aixingfu.sports.Adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.aixingfu.sports.R;
import com.aixingfu.sports.bean.PaymentBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author pengyuming
 * @version 1.0
 * @Package com.pengyuming.myapplication.demo
 * @Description: TODO (用一句话描述该文件做什么) Date: 2017-02-23  09:51
 */
public class PaymentAdapter extends BaseQuickAdapter<PaymentBean, BaseViewHolder> {


    public PaymentAdapter() {
        super(R.layout.item_payment);
    }

    private OnItemEditTextChangedListener mListener;

    public void setListener(OnItemEditTextChangedListener listener) {
        mListener = listener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final PaymentBean item) {
        helper.setText(R.id.tv_payment_method, item.getPayment());
        helper.setText(R.id.ed_money, item.getPrice());
        EditText edPrice = helper.getView(R.id.ed_money);
        LinearLayout llpaymentMethod = helper.getView(R.id.ll_payment_method);
        llpaymentMethod.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemClickListener.onItemClick(helper.getLayoutPosition(),v);
            }
        });
        edPrice.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                mListener.onEditTextAfterTextChanged(s, helper.getLayoutPosition());
            }
        });
    }

    public interface OnItemEditTextChangedListener {
        void onEditTextAfterTextChanged(Editable editable, int position);
    }
    protected OnItemClickListener mItemClickListener;

    public interface OnItemClickListener {
        void onItemClick(int position, View v);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mItemClickListener = listener;
    }
}
